package nz.ac.massey.doi_information_extractor.tests;

import static org.junit.Assert.*;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import nz.ac.massey.doi_information_extractor.data.Publication;
import nz.ac.massey.doi_information_extractor.parser.ScienceDirectPlugin;

import org.junit.Before;
import org.junit.Test;

//This class contains rudimentary tests for the ScienceDirectPlugin class. It's based on http://dx.doi.org/10.1016/j.websem.2006.11.007, one of Jen's papers.

public class ScienceDirectPluginTest {

	Publication newpub;

	@Before
	public void setUp() throws Exception{
		System.setProperty("http.proxyHost", "tur-cache.massey.ac.nz");
		System.setProperty("http.proxyPort", "8080");
		
		//This is the reason the tests take so long.
		ExecutorService pool = Executors.newFixedThreadPool(1);
		Callable<Publication> scienceDirectPlugin = new ScienceDirectPlugin("10.1016/j.websem.2006.11.007");
		Future<Publication> futureBibsonomyPluginResult = pool.submit(scienceDirectPlugin);

		newpub = futureBibsonomyPluginResult.get();
	}

	@Test
	public void tests() throws Exception{
		assertTrue(newpub.getKeywords().equals("Semantic web; Software design patterns; Collaborative software engineering"));
	
		assertTrue(newpub.getUrl().startsWith("http://www.sciencedirect.com/science?_ob=MImg"));
		
		assertTrue(newpub.getVolumeNumber().equals("5"));
		
		assertTrue(newpub.getEdition().equals("2"));
		
		assertTrue(newpub.getDescription().equals("Design patterns have been used successfully in recent years in the software engineering community in order to share knowledge about the structural and behavioural properties of software. There is a growing body of research in the area of design pattern detection and design recovery, requiring a formal description of patterns which can be matched by tools against the software that is to be analysed. We propose a novel approach to the formal definition of design patterns that is based on the idea that design patterns are knowledge that is shared across a community and that is by nature distributed and inconsistent. By using the web ontology language (OWL) we are able to formally define design patterns and some related concepts such as pattern participant, pattern refinement, and pattern instance. We discuss the respective ontology and give examples of how patterns can be defined using this ontology. We present the prototype of a Java client that accesses the pattern definitions and detects patterns ") && (newpub.getDescription().length() <= 1012));
		
		assertTrue(newpub.getDoi().equals("http://dx.doi.org/10.1016/j.websem.2006.11.007"));
	
		assertTrue(newpub.getArticleTitle().equals("Towards a web of patterns"));
		
		assertTrue(newpub.getAuthors().size() == 2);
		
		assertTrue(newpub.getAuthors().get(0).getOrganisation().equals(newpub.getAuthors().get(1).getOrganisation()) && newpub.getAuthors().get(0).getOrganisation().equals("Massey University, Institute of Information Sciences and Technology, Palmerston North, New Zealand"));
		
		assertTrue(newpub.getPublicationTitle().equals("Web Semantics: Science, Services and Agents on the World Wide Web"));
		
		assertTrue(newpub.getPageNumbers().equals("108-116"));
		
		assertTrue(newpub.getDate().equals("June 2007"));
	}
}
